/* 
 * 初始化文件
 */
$(function() {
//title提示
    $(document).tooltip();
    /**
     * 返回
     */
    $('.back_btn').click(function() {
        window.history.back();
    });
    /**
     * 异步更改状态：开启/关闭、显示/隐藏 ...
     */
    $('.js_status').click(function() {
        var jsUrl = $(this).attr('url');
        var $this = $(this);
        $this.attr('disabled', true);
        $this.tyAjax({
            isForm: false,
            type: 'get',
            url: jsUrl,
            callBack: function(data) {
                if (data.status == 1) {
                    if ($this.hasClass("status_enable")) {
                        $this.removeClass("status_enable");
                        $this.addClass("status_disable");
                    } else {
                        $this.removeClass("status_disable");
                        $this.addClass("status_enable");
                    }
                }

                icon = data.status > 0 ? 'succeed' : 'error';
                art.dialog({
                    "icon": icon,
                    "title": '消息',
                    "id": "loadding",
                    "lock": true,
                    "fixed": true,
                    "drag": false
                }).content(data.info).time(1.5);
                
                if(data.url != ''){
                	var interval = setInterval(function() {
                    	clearInterval(interval);
                        window.location.href = data.url;
                    }, jumpTime * 1000);
                }

                $this.attr('disabled', false);
                setTimeout("window.location.reload()",2000)
    
            }
        });
    });

    /**
     * 异步更排序
     */
    $('.js_sort').change(function() {
        //获取变化数值
        var newSort = $(this).val();
        //判断是否非数字
        if (!$.isNumeric(newSort)) {
            art.dialog.tips('请输入数字', 1.5);
            return false;
        }
        var jsUrl = $(this).attr('url');
        $(this).tyAjax({
            isForm: false,
            type: 'get',
            url: jsUrl,
            data: {'sort': newSort},
            callBack: function(data) {
                icon = data.status > 0 ? 'succeed' : 'error';
                art.dialog({
                    "icon": icon,
                    "title": '消息',
                    "lock": true,
                    "fixed": true,
                    "drag": false
                }).content(data.info).time(1.5);
                
                if(data.url != ''){
                	var interval = setInterval(function() {
                    	clearInterval(interval);
                        window.location.href = data.url;
                    }, jumpTime * 1000);
                }
            }
        });
    });
    
    /**
     * 异步更默认众筹量
     */
    $('.js_action_num').change(function() {
        //获取变化数值
        var newSort = $(this).val();
        //判断是否非数字
        if (!$.isNumeric(newSort)) {
            art.dialog.tips('请输入数字', 1.5);
            return false;
        }
        var jsUrl = $(this).attr('url');
        $(this).tyAjax({
            isForm: false,
            type: 'get',
            url: jsUrl,
            data: {'action_num': newSort},
            callBack: function(data) {
                icon = data.status > 0 ? 'succeed' : 'error';
                art.dialog({
                    "icon": icon,
                    "title": '消息',
                    "lock": true,
                    "fixed": true,
                    "drag": false
                }).content(data.info).time(1.5);
                
                if(data.url != ''){
                	var interval = setInterval(function() {
                    	clearInterval(interval);
                        window.location.href = data.url;
                    }, jumpTime * 1000);
                }
            }
        });
    });
    
    /**
     * 异步更众筹时长
     */
    $('.js_action_time').change(function() {
        //获取变化数值
        var newSort = $(this).val();
        //判断是否非数字
        if (!$.isNumeric(newSort)) {
            art.dialog.tips('请输入数字', 1.5);
            return false;
        }
        var jsUrl = $(this).attr('url');
        $(this).tyAjax({
            isForm: false,
            type: 'get',
            url: jsUrl,
            data: {'action_time': newSort},
            callBack: function(data) {
                icon = data.status > 0 ? 'succeed' : 'error';
                art.dialog({
                    "icon": icon,
                    "title": '消息',
                    "lock": true,
                    "fixed": true,
                    "drag": false
                }).content(data.info).time(1.5);
                
                if(data.url != ''){
                	var interval = setInterval(function() {
                    	clearInterval(interval);
                        window.location.href = data.url;
                    }, jumpTime * 1000);
                }
            }
        });
    });
    
    /**
     * 异步更支持时长
     */
    $('.js_support_time').change(function() {
        //获取变化数值
        var newSort = $(this).val();
        //判断是否非数字
        if (!$.isNumeric(newSort)) {
            art.dialog.tips('请输入数字', 1.5);
            return false;
        }
        var jsUrl = $(this).attr('url');
        $(this).tyAjax({
            isForm: false,
            type: 'get',
            url: jsUrl,
            data: {'support_time': newSort},
            callBack: function(data) {
                icon = data.status > 0 ? 'succeed' : 'error';
                art.dialog({
                    "icon": icon,
                    "title": '消息',
                    "lock": true,
                    "fixed": true,
                    "drag": false
                }).content(data.info).time(1.5);
                
                if(data.url != ''){
                	var interval = setInterval(function() {
                    	clearInterval(interval);
                        window.location.href = data.url;
                    }, jumpTime * 1000);
                }
            }
        });
    });

    /**
     * 批量删除
     */
    $(".recover").click(function(e) {
    	$this = $(this);
        form = $(".recover").parents('form');

        $checkboxes = form.find('input[name][type=checkbox]:checked');

        if (form.find('input[name][type=checkbox]')[0] && $checkboxes.length == 0) {
            art.dialog.alert(langjs.select_delete_record);
            return false;
        }else {
        	art.dialog({
                id: 'confirm',
                title: '消息',
                icon: 'question',
                opacity: .1,
                resize: false,
                lock: true,
                fixed: true,
                content: '您真的要删除吗？',
                button: [
                    {
                        name: '确定',
                        callback: function() {
                            this.close();
                            $this.tyAjax({
                                callBack: function(data) {
                                    callBackTips(data.status, data.info, data.url);
                                }
                            });
                            
                            return false;
                        },
                        focus: true
                    },
                    {
                        name: '取消'
                    }
                ]
            });
        }
        
        e.preventDefault();
        //终止事件 不再派发事件
        e.stopPropagation();
    });
    
    /**
     * 批量下架
     */
     $(".issell").click(function(e) {
    	$this = $(this);
        form = $(".issell").parents('form');

        $checkboxes = form.find('input[name][type=checkbox]:checked');

        if (form.find('input[name][type=checkbox]')[0] && $checkboxes.length == 0) {
            art.dialog.alert(langjs.please_select_record);
            return false;
        }else {
        	art.dialog({
                id: 'confirm',
                title: langjs.message,
                icon: 'question',
                opacity: .1,
                resize: false,
                lock: true,
                fixed: true,
                content: langjs.issell_confirm,
                button: [
                    {
                        name: langjs.ok,
                        callback: function() {
                            this.close();
                            $this.tyAjax({
                                callBack: function(data) {
                                    callBackTips(data.status, data.info, data.url);
                                }
                            });
                            
                            return false;
                        },
                        focus: true
                    },
                    {
                        name: langjs.cancle
                    }
                ]
            });
        }
        
        e.preventDefault();
        //终止事件 不再派发事件
        e.stopPropagation();
    });
     
    
    
    
    /**
     * 删除事件
     */
    $('.list_table a.delete').click(function(e) {
        var url = $(this).attr('href');
        var $this = $(this);
        var tips = $(this).attr('tips');
        if (tips == null) {
            tips = '您真的要删除吗？';
        }

        art.dialog({
            id: 'confirm',
            title: '消息',
            icon: 'question',
            opacity: .1,
            resize: false,
            lock: true,
            fixed: true,
            content: tips,
            button: [
                {
                    name: '确定',
                    callback: function() {
                        this.close();
                        $this.tyAjax({
                            isForm: false,
                            url: url,
                            callBack: function(data) {
                                icon = data.status > 0 ? 'succeed' : 'error';
                                art.dialog({
                                    "icon": icon,
                                    "title": '消息',
                                    "id": "loadding",
                                    "lock": true,
                                    "fixed": true,
                                    "drag": false
                                }).content(data.info).time(1);

                                if (data.status) {
                                    $this.parents('tr').hide(1000);

//                                    var interval = setInterval(function() {
//                                    	clearInterval(interval);
//                                        window.location.reload();
//                                    }, jumpTime * 1000);
                                }
                            }
                        });
                        return false;
                    },
                    focus: true
                },
                {
                    name: '取消'
                }	
            ]
        });
        e.preventDefault();
        //终止事件 不再派发事件
        e.stopPropagation();
    });
    
    

    
    /**
     * 初始化tag标签
     */
    $('.tab_box').children().each(function() {
        $(this).css('display', 'none');
    });
    $('.tab_box>table:first').css('display', '');
    /**
     * tag标签切换
     */
    $(".tab_list>li").click(function() {
        $(this).parent().children().removeClass('tab_active');
        $(this).addClass('tab_active');
        var num = $("li").index(this) + 1;
        $('.tab_box').children().css('display', 'none');
        $('#box-' + num).css({'opacity': 0, 'display': ''}).animate({opacity: 1}, 500);
    });
    /**
     * 绑定全选事件
     */
    checkAll('.check_all', '.check_one');

});

